<template>
	<view>
		<view class="tags-box">
			<u-sticky bgColor="#fff">
				<u-tabs
					:list="list1"
					@click="click"
					lineColor="#FFFFFF"
					:activeStyle="{
						color: '#222',
						fontWeight: 'bold',
						transform: 'scale(1.05)'
					}"
				></u-tabs>
			</u-sticky>
		</view>
		<view class="wire"></view>

		<view class="list-box">
			<view class="each-box" v-for="i in recruitList">
				<view class="each-box-content">
					<view class="title-box">
						<view class="title">{{i.title}}</view>
						<view class="price">{{i.salary}}</view>
					</view>
					<view class="name-box">
						<view class="name">
							<!-- <image src="../../../static/wx.png" mode=""></image> -->
							{{i.company}}
						</view>
						<view class="time">{{i.updatetime}}</view>
					</view>
				</view>
				<!-- <view class="operation" v-if="status == 1 || status == 2">
					<view class="">编辑</view>
					<view class="" @click="grounding(i.id,'up')" v-if="status == 2">上架</view>
					<view class="" @click="grounding(i.id,'lower')" v-if="status == 1">下架</view>
				</view> -->
				<view class="operation">
					<view class="" @click="compile(i.id)" v-if="status == 1 || status == 2 || status==-1">编辑</view>
					<view class="" @click="top(i.id)" v-if="status == 1">置顶</view>
					
					<view class="" @click="grounding(i.id,'up')" v-if="status == 2">上架</view>
					<!-- <view class="" @click="grounding(i.id,'lower')" v-if="status == 1">下架</view> -->
					<view class="" @click="down(i.id,'lower')" v-if="status == 1">下架</view>
				</view>
				
				<view class="operation">
					<view class="" v-if="i.switch == 1">置顶到期时间：{{i.toptime | date('yyyy-mm-dd hh:MM')}}</view>
				</view>
			</view>
			<u-empty v-if="recruitList.length === 0" mode="data" marginTop="100">
			</u-empty>
		</view>
		
		<TopPopup :show1="show" :meal="meal" @ckeck="ckeck" @padlock="show = false" :title="false"></TopPopup>
	</view>
</template>

<script>
	import TopPopup from "@/components/topPopup.vue"
export default {
	components: { TopPopup },
	data() {
		return {
			list1: [
				{ name: '发布中', state: 1 },
				{ name: '已下架', state: 2 },
				{ name: '待审核', state: 0 },
				{ name: '审核拒绝', state: -1 }
			],
			page:1,
			status:1,
			recruitList:[],
			
			meal: [],
			id:'',
			itemid:'',
			show:false,
			current:null,
			
			myMoney:'',
			paytype:null
		};
	},
	onLoad() {
		// this.getrecruitInfoList()
		this.getMoney()
		// #ifdef MP-WEIXIN
		this.paytype = 2
		// #endif
		// #ifdef APP
		this.paytype = 1
		// #endif
	},
	onShow() {
		this.page = 1
		this.recruitList = []
		this.getrecruitInfoList()
		this.getcombo()
	},
	methods: {
		getMoney(){
			uni.$u.http.post('/getmoney ').then(res => {
				if (res.code === 1) {
					this.myMoney = res.data
				}
			}).catch((res) => {
				
			})
		},
		cutitem(i,id){
			this.current = i
			this.itemid = id
		},
		getcombo() {
			uni.$u.http.post('/meallist',{
				mealtype:5
			}).then(res => {
				if (res.code == 1) {
					this.meal = res.data
				}
			}).catch((res) => {
			})
		},
		//置顶
		top(id){
			this.id = id
			this.show = true
		},
		ckeck(e) {
			if(!e.id) return this.toast('请选择置顶套餐')
			if(this.myMoney < e.money){
				//余额不足 微信支付
				uni.$u.http.post('/meallist', {
					type:5,
					order_id: this.id,
					id:e.id,
					paytype:this.paytype
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						let that = this
						uni.requestPayment({
							appId: res.data.pay.appId,
							nonceStr: res.data.pay.nonceStr,
							package: res.data.pay.package,
							paySign: res.data.pay.paySign,
							signType: res.data.pay.signType,
							timeStamp: res.data.pay.timeStamp,
							success: (e) => {
								that.toast(res.msg)
								that.show = false
								setTimeout(() => {
									uni.navigateBack()
								},500)
							},
							fail: (e) => {
								that.$u.toast('支付失败');
							}
						})
					}
				}).catch((res) => {
						
				})
			}else {
				//余额支付
				uni.$u.http.post('/meallist', {
					type:5,
					order_id: this.id,
					id:e.id,
					paytype:4
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.toast(res.msg)
						this.show = false
						setTimeout(() => {
							uni.navigateBack()
						},500)
					}
				}).catch((res) => {
						
				})
			}
			
			// if(!this.itemid) return this.toast('请选择置顶套餐')
			// uni.$u.http.post('/meallist', {
			// 	type:5,
			// 	order_id: this.id,
			// 	id: this.itemid
			// }).then(res => {
			// 	console.log(res)
			// 	if (res.code == 1) {
			// 		this.toast(res.msg)
			// 		this.show = false
			// 		this.page = 1
			// 		this.finish = false
			// 		this.recruitList = []
			// 		this.getrecruitInfoList()
			// 	}
			// }).catch((res) => {
			
			// })
		},
		//下架
		down(id,type) {
			let that = this
			uni.showModal({
				title: '温馨提示',
				content: '信息下架置顶状态会消失',
				success: function(res) {
					if (res.confirm) {
						that.grounding(id,type)
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		},
		//编辑
		compile(id){
			uni.navigateTo({
				url:'/pages/newissue/recruit?id='+id
			})
		},
		grounding(id,type){
			uni.$u.http.post('/recruit/postRecruit',{
				id,
				type
			}).then(res => {
				if (res.code == 1) {
					this.recruitList = []
					this.page = 1
					this.$u.toast(res.msg);
					this.getrecruitInfoList()
				}
			}).catch((res) => {
			
			})
		},
		getrecruitInfoList(){
			uni.$u.http.post('/recruit/userRecruitList',{
				page:this.page,
				status:this.status
			}).then(res => {
				if (res.code == 1) {
					this.recruitList = this.recruitList.concat(res.data)
				}
			}).catch((res) => {
			
			})
		},
		click(item) {
			this.status = item.state
			this.recruitList = []
			this.page = 1;
			this.getrecruitInfoList()
		}
	}
};
</script>

<style lang="scss">
.tags-box {
	display: flex;
	align-items: center;
	justify-content: center;
}
.wire {
	width: 750rpx;
	height: 0rpx;
	opacity: 1;
	border: 1rpx solid #f0f0f0;
}

.list-box {
	margin: 40rpx 30rpx;
	.each-box {
		.each-box-content {
			width: 622rpx;
			background-color: #f6f6f6;
			border-radius: 24rpx 24rpx 0rpx 0rpx;
			padding: 32rpx;
			margin: auto;
			margin-top: 24rpx;
		}
		.operation {
			display: flex;
			justify-content: space-around;
			align-items: center;
			font-size: 24rpx;
			padding: 0 0 24rpx 0;
			border-radius: 0rpx 0rpx 24rpx 24rpx;
			background-color: #F6F6F6;
		}
		.title-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;
				text {
					width: 58rpx;
					height: 34rpx;
					background: #febf4e;
					border-radius: 4rpx 4rpx 4rpx 4rpx;
					opacity: 1;
					font-size: 24rpx;
					text-align: center;
					line-height: 34rpx;
					font-weight: 500;
					color: #333333;
					margin-right: 10rpx;
				}
			}
			.price {
				font-size: 30rpx;
				font-weight: 800;
				color: #fa6759;
			}
		}
		.name-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 32rpx;
			.name {
				font-size: 26rpx;
				font-weight: 500;
				color: #666666;
				image {
					width: 34rpx;
					height: 34rpx;
					border-radius: 50%;
					opacity: 1;
					vertical-align: middle;
					margin-right: 16rpx;
				}
			}
			.time {
				font-size: 22rpx;
				font-weight: 500;
				color: #999999;
			}
		}
	}
}


.serveBox {
		width: 690rpx;
		border-radius: 20rpx;
	
		.serve_tit {
			margin-top: 30rpx;
			text-align: center;
			font-size: 36rpx;
			color: #333333;
			font-weight: bold;
			line-height: 40rpx;
		}
		
		.tc-img {
			width: 600rpx;
			margin: auto;
			image {
				width: 600rpx;
				height: 500rpx;
			}
		}
		
		.serve_cont {
			// margin: 0 30rpx;
			display: flex;
			// flex-wrap: wrap;
			// flex-direction: row;
			
			margin-top: 24rpx;
			overflow: hidden;
			overflow-x: auto;
			white-space: nowrap;
	
	
			.serve {
				margin: 30rpx 0;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-right: 20rpx;
				padding: 16rpx 32rpx;
				// width: 190rpx;
				// height: 200rpx;
				box-sizing: border-box;
				border-radius: 20rpx;
				border: 1rpx solid #989898;
	
	
				.serve_num {
					margin-bottom: 20rpx;
					font-size: 30rpx;
					font-weight: bold;
					color: #333;
					line-height: 45rpx;
				}
	
				.serve_hour {
					font-size: 28rpx;
					font-weight: 400;
					color: #323232;
					line-height: 40rpx;
				}
			}
	
			.active {
				border: 2px solid #FF7A7A !important;
			}
	
		}
		
		.tc-btn-box {
			width: 560rpx;
			margin: auto;
			margin-top: 20rpx;
			display: flex;
			justify-content: space-between;
			.tc-btn1 {
				width: 220rpx;
				height: 80rpx;
				background-color: #FBBA45;
				border-radius: 10rpx;
				text-align: center;
				line-height: 80rpx;
			}
			.tc-btn2 {
				width: 220rpx;
				height: 80rpx;
				border-radius: 10rpx;
				text-align: center;
				line-height: 80rpx;
				background-color: #9A9A9A;
				color: #FFF;
			}
		}
	
	}
</style>
